package com.cp.admin.api.entity;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2017/11/24 17:21
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "响应码", required = true)
    private int code = CodeEnum.SUCCESS.getCode();//响应码，默认成功

    @ApiModelProperty(value = "响应消息", required = true)
    private String message = CodeEnum.SUCCESS.getMsg();//响应消息

    @ApiModelProperty(value = "结果对象", required = true)
    private T data = null;//结果对象

    @ApiModelProperty(hidden=true)
    private Boolean success;

    public Result() {
    }

    public Boolean isSuccess(){
        return CodeEnum.SUCCESS.getCode()==code;
    }
    public Boolean isFail(){

        return CodeEnum.SUCCESS.getCode()!=code;
    }

    public Result(T data){
        this(CodeEnum.SUCCESS.getCode(),CodeEnum.SUCCESS.getMsg(),data);
    }

    public Result(CodeEnum codeEnum) {
        this.code = codeEnum.getCode();
        this.message = codeEnum.getMsg();
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
